package cate.game.attr;

import cate.game.play.support.PlayBuildContext;
import cate.game.role.bag.spice.Spice;
import cate.game.role.bag.spice.SpiceVO;
import cate.game.role.bag.spice.SpicesOn;

import java.util.Map;

public class SpicesPowerAttrPart extends PowerAttrPart {
    public SpicesPowerAttrPart(){}

    public SpicesPowerAttrPart(PlayBuildContext ctx, SpicesOn po) {
        if (po.owner == null) {
            return;
        }
        if (po.owner.getRole() == null) {
            return;
        }
        FightAttr attr = new FightAttr();
        this.powerExt = 0;
        if (po.spiceMap != null) {
            for (Map.Entry<Byte, String> entry : po.spiceMap.entrySet()) {
                Spice spice = po.getPosItems(entry.getKey());
                if (spice == null) {
                    if (po.spiceData != null) {
                        SpiceVO vo = po.spiceData.get(entry.getValue());
                        if (vo != null) {
                            attr.add(vo.getPowerAttr(ctx));
                        }
                    }
                } else {
                    attr.add(spice.getPowerAttr(ctx));
                }
            }
        }
        this.attr = attr;
        this.skills = po.getSkills(ctx);
    }
}
